package com.ticket.common.utils.wechat.sdk;


import java.util.LinkedHashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * 统一下单
 * 
 * @author ZQM
 *
 */
public class UnifiedorderReqData extends AbstractRequestProtocol {
	private String appid = "";
	private String mch_id = "";
	private String device_info = "";
	private String nonce_str = "";
	private String sign = "";
	private String body = "";
	private String detail = "";
	private String attach = "";
	private String out_trade_no = "";
	private int total_fee = 0;
	private String spbill_create_ip = "";
	private String time_start = "";
	private String time_expire = "";
	private String goods_tag = "";
	private String notify_url = "";
	private String trade_type = "JSAPI";
	private String product_id = "";
	private String limit_pay = "";
	private String openid = "";

	public UnifiedorderReqData(String device_info, String body, String detail,
                               String attach, String out_trade_no, int total_fee,
                               String spbill_create_ip, String time_start, String time_expire,
                               String goods_tag, String notify_url, String trade_type,
                               String product_id, String limit_pay, String openid) {
		// 微信分配的公众号ID（开通公众号之后可以获取到）
		setAppid(Configure.getAppid());
		// 微信支付分配的商户号ID（开通公众号的微信支付功能之后可以获取到）
		setMch_id(Configure.getMchid());
		this.device_info = device_info;
		this.body = body;
		this.detail = detail;
		this.attach = attach;
		this.out_trade_no = out_trade_no;
		this.total_fee = total_fee;
		this.spbill_create_ip = spbill_create_ip;
		this.time_start = time_start;
		this.time_expire = time_expire;
		this.goods_tag = goods_tag;
		this.notify_url = notify_url;
		this.trade_type = trade_type;
		this.product_id = product_id;
		this.limit_pay = limit_pay;
		this.openid = openid;

		// 随机字符串，不长于32 位
		setNonce_str(RandomStringGenerator.getRandomStringByLength(32));

		// 根据API给的签名规则进行签名
		setSign(PayCommonUtil.createSign("UTF-8",toSignMap()));
		//setSign(Signature.getSign(toMap()));// 把签名数据设置到Sign这个属性中
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getMch_id() {
		return mch_id;
	}

	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}

	public String getDevice_info() {
		return device_info;
	}

	public void setDevice_info(String device_info) {
		this.device_info = device_info;
	}

	public String getNonce_str() {
		return nonce_str;
	}

	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getAttach() {
		return attach;
	}

	public void setAttach(String attach) {
		this.attach = attach;
	}

	public String getOut_trade_no() {
		return out_trade_no;
	}

	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}

	public int getTotal_fee() {
		return total_fee;
	}

	public void setTotal_fee(int total_fee) {
		this.total_fee = total_fee;
	}

	public String getSpbill_create_ip() {
		return spbill_create_ip;
	}

	public void setSpbill_create_ip(String spbill_create_ip) {
		this.spbill_create_ip = spbill_create_ip;
	}

	public String getTime_start() {
		return time_start;
	}

	public void setTime_start(String time_start) {
		this.time_start = time_start;
	}

	public String getTime_expire() {
		return time_expire;
	}

	public void setTime_expire(String time_expire) {
		this.time_expire = time_expire;
	}

	public String getGoods_tag() {
		return goods_tag;
	}

	public void setGoods_tag(String goods_tag) {
		this.goods_tag = goods_tag;
	}

	public String getNotify_url() {
		return notify_url;
	}

	public void setNotify_url(String notify_url) {
		this.notify_url = notify_url;
	}

	public String getTrade_type() {
		return trade_type;
	}

	public void setTrade_type(String trade_type) {
		this.trade_type = trade_type;
	}

	public String getProduct_id() {
		return product_id;
	}

	public void setProduct_id(String product_id) {
		this.product_id = product_id;
	}

	public String getLimit_pay() {
		return limit_pay;
	}

	public void setLimit_pay(String limit_pay) {
		this.limit_pay = limit_pay;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public SortedMap<Object,Object> toSignMap() {
		SortedMap<Object,Object> map = new TreeMap<Object,Object>();
		map.put("appid",appid);
		map.put("mch_id",mch_id);
		map.put("nonce_str",nonce_str);
		map.put("body",body);
		map.put("out_trade_no",out_trade_no);
		map.put("total_fee",total_fee);
		map.put("spbill_create_ip",spbill_create_ip);
		map.put("notify_url",notify_url);
		map.put("trade_type",trade_type);
		map.put("openid",openid);
		return map;
	}

	public Map<String,Object> toStringMap() {
		Map<String,Object> map = new LinkedHashMap <String,Object>();
		map.put("appid",appid);
		map.put("mch_id",mch_id);
		map.put("nonce_str",nonce_str);
		map.put("sign",sign);
		map.put("body",body);
		map.put("out_trade_no",out_trade_no);
		map.put("total_fee",total_fee);
		map.put("spbill_create_ip",spbill_create_ip);
		map.put("notify_url",notify_url);
		map.put("trade_type",trade_type);
		map.put("openid",openid);
		return map;
	}
}
